Repository navigation
Conversation
…d_files A file input with the multiple attribute sends several files under the same field name, but uploaded files were stored in a HashMap keyed by field name, so only the last one was kept. - RequestInfo::uploaded_files keeps every file in an UploadedFiles list. get(name) still returns a single file (the last one), so existing functions behave as before; all(name) returns every file of a field (name[] also matches name). - New sqlpage.persist_uploaded_files(field, folder, extensions, mode): persists all the files of a field and returns their paths as a JSON array (NULL when no file was sent). Extensions are all checked before anything is written. - Tests, function documentation, form 'multiple' documentation, changelog.
test_persist_uploaded_files_rejects_all_on_bad_extension counted the files of tests/uploads/persisted_multiple, where test_persist_uploaded_files writes concurrently, so it failed when both tests overlapped (seen on the MSSQL job).
Collaborator
|
Thanks ! Two things:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The form component already renders
multipleon file inputs, so users can pick several files at once.But the server stores uploaded files in a
HashMap<String, TempFile>keyed by field name: when a fieldsends several files, only the last one survives, and there is no way to reach the others from SQL.
This makes it impossible to build "upload all your photos at once" forms, a common need on mobile.
Change
RequestInfo::uploaded_filesis now anUploadedFileslist that keeps every file, in the order it was received.get(name)keeps the previous behavior: one file per field, the last one if several were sent. All existingfunctions (
uploaded_file_path,uploaded_file_name,uploaded_file_mime_type,persist_uploaded_file,CSV import) behave exactly as before.
all(name)returns every file of a field.name[]also matchesname, following the convention used formulti-value form fields.
sqlpage.persist_uploaded_files(field, destination_folder, allowed_extensions, mode). It has the sameparameters and the same security notes as
persist_uploaded_file, and returns the paths as a JSON array, or NULLwhen no file was sent. Every extension is checked before anything is written, so a rejected file leaves no partial
upload behind.
persist_uploaded_filewas split into small helpers (allowed_extension,persist_file) shared by both functions.It has no behavior change.
Tests and docs
photos[]. Both are kept in order, andgetstill returns the last one.79_persist_uploaded_files.sql);multipleproperty now mentions file inputs;cargo fmt --check,cargo clippy --all-targetsand the upload tests pass locally.I use this in a coin-collection app where users send dozens of phone photos in one go.